<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath() ;
    String authServerPath  =(String)request.getSession().getAttribute("authServerPath");
%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" class="entryPage">
<head>
    <meta charset="UTF-8">
    <title>狮桥融资租赁系统</title>
    <link rel="shortcut icon" href="<%=path %>/resource/lib/images/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="<%=path %>/resource/lib/ligerUI/skins/Aqua/css/ligerui-all.css" />
    <link rel="stylesheet" type="text/css" href="<%=path %>/resource/lib/ligerUI/skins/sqBlue/css/all.css">
    <link rel="stylesheet" type="text/css" href="<%=path %>/resource/lib/plugins/nanoScrollerJS/css/nanoscroller.css">
   	<script src="<%=path %>/resource/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="<%=path %>/resource/lib/plugins/jquery.cookie.js" type="text/javascript"></script>
    <script src="<%=path %>/resource/utils/CookieUtils.js" type="text/javascript"></script>
</head>
<body>
<div id="pageloading"></div>
<div class="Wrapper">
    <div id="layout1">
        <div class="headNnav">
            <div class="l-topmenu">
                <div class="topIn">
                    <div class="l-topmenu-logo">狮桥融资租赁系统</div>
                    
                    <sys:indexWelcome/>
                    
                    <!-- <div class="l-topmenu-welcome">
                        <ul>
                            <li class="userAvatarBox">
                                <a href="javascript:;" class="userAvatar"><img src="../demos/images/defaultUserAvatar.jpg"></a>
                                <div  class="dropdown">
                                <ul>
                                    <li><a href="javascript:;"><i class="topNavico_spirit topNavico_1"></i>密码设置</a></li>
                                    <li><a href="javascript:;"><i class="topNavico_spirit topNavico_2"></i>权限设置</a></li>
                                    <li><a href="javascript:;"><i class="topNavico_spirit topNavico_3"></i>个人信息</a></li>
                                    <li><a href="javascript:;"><i class="topNavico_spirit topNavico_4"></i>皮肤</a></li>
                                    <li><a href="javascript:;"><i class="topNavico_spirit topNavico_5"></i>注销</a></li>
                                </ul>
                                </div>
                            </li>
                            <li>
                                <span>信审员</span>
                            </li>
                            <li class="bar">|</li>
                            <li>
                                <a href="javascript:;">张倩</a>
                                <span>，您好！</span>
                            </li>
                            <li class="more">
                                <span class="moreBtn"></span>
                                <div  class="dropdown">
                                <ul>
                                    <li>
                                        <a href="javascript:;">
                                            <span class="userAvatar"><img src="../demos/images/defaultUserAvatar.jpg"></span>
                                            <span class="userName">张倩</span>
                                        </a>
                                    </li>
                                    <li>
                                        <span>狮桥资本</span>
                                        <span class="bar">|</span>
                                        <span>重卡事业部</span>
                                    </li>
                                    <li>
                                        <span>北京分公司</span>
                                        <span class="bar">|</span>
                                        <span>信审员</span>
                                    </li>
                                </ul>
                                </div>
                            </li>
                        </ul>
                    </div> -->
                </div>
            </div>
            <div class="mainNav">
                <div class="navIn"><span id="sideToggle"></span></div>
            </div>
        </div>
        <div class="homeBk_Btn"><a>首页</a></div>
        <div class="sideNav">
            <div class="sideNav_BG"></div>
            <div class="nano"><div class="nano-content">
            	<!-- 系统菜单 -->
            	<sys:indexMenu></sys:indexMenu>
            </div></div>
        </div>
        <div id="framecenter">
            <div tabid="home" title="首页">
                <iframe frameborder="0" name="home" id="home" src="<%=path %>/login/login/toMainPage.do"></iframe>
            </div>
            <!-- <div tabid="mytask" title="我的任务">
                <iframe frameborder="0" name="mytask" id="mytask" src=""></iframe>
            </div> -->
        </div>
    </div>
</div>

<!-- 我的角色 -->
<div id="myOrgRole_Html" style="display:none">
    <div id="ligergrid_myOrgRole" class="sq-grid"></div>
    <div class="btnsBox TC">
        <span class="sq-button sq-button-hasicon l-dialog-btn-ok"><i class="sqBtnIco_30"></i>确认</span>
        <span class="sq-button sq-button-hasicon l-dialog-btn-cancel"><i class="sqBtnIco_14"></i>取消</span>
    </div>
</div>

<script src="<%=path %>/resource/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="<%=path %>/resource/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
<script src="<%=path %>/resource/lib/require.js" type="text/javascript"></script>
<script src="<%=path %>/resource/lib/plugins/jquery.cookie.js" type="text/javascript"></script>
<script src="<%=path %>/resource/lib/plugins/nanoScrollerJS/js/jquery.nanoscroller.js" type="text/javascript"></script>
<script src="<%=path %>/resource/lib/plugins/json2.js" type="text/javascript"></script>
<script src="<%=path %>/resource/lib/requireConfig.js" type="text/javascript"></script>
<script src="<%=path %>/resource/lib/SQ.js" type="text/javascript"></script>

<script type="text/javascript">

    window.mainApp = {}  // 给iframe（子页面）调用的接口
    var grid_myOrgRole;
    var defaultOrgId;
    var defaultRoleId;
    var tab = null;
    var accordion = null;
    var tree = null;
    var tabItems = [];
    var navTabCompleted = false,
        isShowSideNav = true,
        lastSelected2TabID = new Array(2), //保存最后两次选中的Nav的tabid
        $sideNav = $('.sideNav'),
        headNnav_H = $('.l-topmenu').height() + $('.mainNav').height();

    $(function() {
    	
    	//请求是否需要修改密码
    	$.ajax({
			type: 'get',
			dataType:'json',
			data:{},
			url: '<%=path%>/system/sysUsr/checkIsDefPwd.do',
			success:function(msg){
				 if(msg.success == 1){
					 //修改密码
					 top.$.ligerDialog.SQopen({
			              width: 500,
			              height:200,
			              allowClose:false,
			              title : '修改密码',
			              url:'<%=path%>/system/sysUsr/toUsrPwdModifyPage.do?',
			              buttons: [{
				                  text: "确认", type: 'ok', cls: 'sq-button sq-button-round',
				                  onclick: function (item, Dialog) {
				                      if (Dialog.onOkForIndex){
				                          Dialog.onOkForIndex();
                                      }
				                  }
				              }
				          ]
			          });
				 }
			}
		});

        //Tab
        $("#framecenter").ligerTab({
            height: 'auto',
            showSwitchInTab: true,
            showSwitch: false,
            changeHeightOnResize : true,
            isFixedFirstTab: true,       //针对Shiqiao租赁系统Home Tab 固定
            minIframeHeight: $(window).height() - headNnav_H -5,
            onAfterAddTabItem: function(tabdata) {
                tabItems.push(tabdata);
                saveTabStatus();
                $(window).resize();
            },
            onBeforeRemoveTabItem : function (tabid) {
                if (tab.getSelectedTabItemID() == tabid) {
                    tab.selectTabItem(lastSelected2TabID[0]);
                };
            },
            onAfterRemoveTabItem: function(tabid) {
                for (var i = 0; i < tabItems.length; i++) {
                    var o = tabItems[i];
                    if (o.tabid == tabid) {
                        tabItems.splice(i, 1);
                        saveTabStatus();
                        changeSideNav (tab.getSelectedTabItemID());
                        setTabContent ();
                        break;
                    }
                }
            },
            onAfterSelectTabItem : function (tabid) {
                if (navTabCompleted) {
                    changeSideNav (tabid);
                    setTabContent ();
                };
                lastSelected2TabID.shift();
                lastSelected2TabID.push(tabid);
            }
        });

        //面板
        $("#accordion1").ligerAccordion({
            height: "auto",
            speed: 200,
            opened: false,
            onAfterRenderAccordion: function () {
                setNanoScroller ();
            },
            onAfterToggleAccordion: function () {
                setNanoScroller ();
            }
        });

        tab = liger.get("framecenter");
        accordion = liger.get("accordion1");
        $("#pageloading").hide();

        pages_init();

        $('.homeBk_Btn').click(function() {
            tab.selectTabItem('home');
            tab.moveToTabItem('home');
        });
        $('#accordion1').on('click', '.l-link', function(event) {
            var url  =$(this).attr('data-url');
            var tempUrl  =$(this).attr('temp-url');
            if("null" != tempUrl){
                window.open(tempUrl,true);
                return;
            }
            if ($(this).attr('data-method') == 'f_addTab')
            {
                event.preventDefault();
                var tabid=$(this).attr('tabid'),
                    text =$(this).attr('title');
                f_addTab(tabid, text, url);
                changeSideNav (tabid);
            };
        });
        if (isShowSideNav) {
            showSideNav ();
        }else{
            closeSideNav ();
        };
        $("#sideToggle").click(function() {
            if (!isShowSideNav) {
                showSideNav ();
                $('#layout1').addClass('showSideNav');
            } else {
                closeSideNav ();
                $('#layout1').removeClass('showSideNav');
            };
            isShowSideNav = !isShowSideNav;
        });

        var resizeTimer = null;
        $(window).resize(function(event) {
            if (resizeTimer) clearTimeout(resizeTimer);
            resizeTimer = setTimeout(function () {
                tab.onResize();
                setSideNavHeight ();
                setNanoScroller ();
            }, 200);
        });

        $.extend(true, window.mainApp, {
            parentTab : tab,
            setTabContent : setTabContent,
            f_addTab : f_addTab
        });
        
        //切换用户角色事件
        $('span[name=span_index_welcome_role_btn_name]').click(function() {
        	var _roleId = $(this).attr("roleId");
        	var _orgId = $(this).attr("orgId");
            var _sysCd,_SQID;
            var cookies =$.cookie('webSQID');
            if(cookies){
                var split = cookies.split("_");
                if(2 === split.length){
                    _sysCd = split[0];
                    _SQID = split[1];
                }
            }
        	//调用后台切换方法, 然后刷新页面
        	$.ligerDialog.confirm('确定要切换当前角色吗?', function (flag) {
    			if(flag == false)return;
    			$.ajax({
    				type: 'post',
    				dataType:'json',
                    data: {
                        roleId: _roleId,
                        orgId: _orgId,
                        sysCd: _sysCd,
                        SQID: _SQID
                    },
                    url: <%=authServerPath%>+"/user/sysUsr/modifyCurrentLoginUserInfo.do",
    				success:function(msg){
    					 if(msg.success == 1){
    						 $.cookie("liger-home-tab", "", {path:'/'});
    						 window.location.reload();
    					 }else if(msg.success==403) {
                             window.location.href = "<%=path%>/login/login/toLoginPage.do";
                         } else{
    						 ligerDialogSuc(msg.info, 3000);
    					 }
    				}
    			});
    		});
        });
        
      //注销
      $('#span_index_welcome_loginout_btn_id').click(function() {
          $.ligerDialog.SQopen({
              cls: 'noBorder_Dialog',
              width: 750,
              height: 400,
              title: '用户注销',
              url: '<%=path%>/system/sysUsr/toUsrLoginOutPage.do',
              // 自定义buttons的时候 不要设置 fixButtons: true
              buttons: [{
                  text: "保存", type: 'ok', cls: 'l-dialog-btn-no',
                  onclick: function (item, Dialog) {
                      debugger
                      //在子页面里绑定 frameElement.dialog.onOk = function () {}
                      if (Dialog.onOk) {
                          Dialog.onOk(function (flag) {
                              //调用完成操作
                              if (flag == true) {
                                  $.cookie("liger-home-tab", "", {path:'/'});
                                  window.location.reload();
                              }
                          });
                      }
                  }
              }, {
                  text: "取消", type: 'cancel', cls: 'l-dialog-btn-ok',
                  onclick: function (item, Dialog) {
                      //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                      if (Dialog.onCancel) Dialog.onCancel();
                  }
              }
              ]
          });
        });

        //用户退出
        $('#span_index_welcome_exit_btn_id').click(function() {
            $.ligerDialog.confirm('确定要退出系统吗?', function (flag) {
                if(flag == false)return;
                usrLoginOut();
            });
        });
      //修改密码
      $('#span_index_welcome_pwdModify_btn_id').click(function() {
    	  $.ligerDialog.SQopen({
              width: 500,
              height:200,
              title : '修改密码',
              url:'<%=path%>/system/sysUsr/toUsrPwdModifyPage.do?',
              buttons: [{
	                  text: "确认", type: 'ok', cls: 'sq-button sq-button-round',
	                  onclick: function (item, Dialog) {
	                      if (Dialog.onOk) Dialog.onOk();
	                  }
	              }, {
	                  text: "取消", type: 'cancel', cls: 'sq-button sq-button-round',
	                  onclick: function (item, Dialog) {
	                      if (Dialog.onCancel) Dialog.onCancel();
	                  }
	              }
	          ]
          });
		});

        //待办提醒
        $('#span_index_welcome_sendFlowMsg_btn_id').click(function() {
                $.ligerDialog.SQopen({
                    width: 500,
                    height:200,
                    title : '短信设置',
                    url:'<%=path%>/notice/sysFlowNoticeCfg/toModifyPage.do?',
                    buttons: [{
                        text: "确认", type: 'ok', cls: 'sq-button sq-button-round',
                        onclick: function (item, Dialog) {
                            if (Dialog.onOk) Dialog.onOk();
                        }
                    }, {
                        text: "取消", type: 'cancel', cls: 'sq-button sq-button-round',
                        onclick: function (item, Dialog) {
                            if (Dialog.onCancel) Dialog.onCancel();
                        }
                    }
                    ]
                });
            });

        //手机号修改
        $('#span_index_welcome_modModify_btn_id').click(function() {
            $.ligerDialog.SQopen({
                width: 500,
                height:200,
                title : '手机号设置',
                url:'<%=path%>/system/sysUsr/initUsrMp.do?',
                buttons: [{
                    text: "确认", type: 'ok', cls: 'sq-button sq-button-round',
                    onclick: function (item, Dialog) {
                        if (Dialog.onOk) Dialog.onOk();
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'sq-button sq-button-round',
                    onclick: function (item, Dialog) {
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
                ]
            });
        });

        //设置默认角色
        $('#span_index_welcome_setDefaultOrgRole_btn_id').click(function() {
            $.ligerDialog.SQopen({
                width: 620,
                top: 25,
                title : '我的角色',
                target: $("#myOrgRole_Html")
            });
            render_ligergrid_myOrgRole ();
        });
    });

    //设置默认角色-初始化列表
    function render_ligergrid_myOrgRole () {
        grid_myOrgRole = $("#ligergrid_myOrgRole").ligerGrid({
            url: '<%=path%>/system/sysUsrFunAuthR/getUsrFunAuthRList.do',
            method : 'get',
            usePager:false,
            root:'rows',
            record:'total',
            rownumbers:true,
            columns: [{
                display: '角色名称',
                name: 'orgRoleNm',
                minWidth: 100
            }, {
                display: '操作',
                isSort: false,
                width: 150,
                align: 'center',
                render: function (rowdata, rowindex, value) {
                    var h = "";
                    if(rowdata.isDefault==1){
                        h += '<span class="sq-button-hasicon">登陆后默认</span>';
                    }else {
                        h += '<a class="sq-button-hasicon" href="javascript:setDefaultOrgRole(';
                        h += "'" + rowdata.id + "'";
                        h += ')">设置为默认</a>';
                    }
                    return h;
                }
            }],
            width: '100%',
            height:'400px',
            heightDiff:-2
        });
        grid_myOrgRole.setHeight(100);
    }

    //设置默认角色
    function setDefaultOrgRole(_id) {
        $.ajax({
            type: 'post',
            dataType:'json',
            data:{id:_id},
            url: '<%=path%>/system/sysUsrFunAuthR/setDefaultOrgRole.do',
            success:function(msg){
                if(msg.success == 1){
                    defaultRoleId = msg.data.roleId;
                    defaultOrgId = msg.data.orgId;
                    top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
                    grid_myOrgRole.reload();
                }else{
                    top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
    }

    //设置默认角色，切换角色
    $("#myOrgRole_Html .l-dialog-btn-ok").click(function() {
        var _roleId =defaultRoleId;
        var _orgId = defaultOrgId;
        if(_roleId == null  || _roleId == '' || _orgId == null || _orgId == ''){
            top.$.ligerDialog.SQalert({content: "请设置默认角色！",SQ_type: "error"});
            return;
        }
        var _sysCd,_SQID;
        var cookies =$.cookie('webSQID');
        if(cookies){
            var split = cookies.split("_");
            if(2 === split.length){
                _sysCd = split[0];
                _SQID = split[1];
            }
        }
        //调用后台切换方法, 然后刷新页面
        $.ajax({
            type: 'post',
            dataType:'json',
            data: {
                roleId: _roleId,
                orgId: _orgId,
                sysCd: _sysCd,
                SQID: _SQID
            },
            url: <%=authServerPath%>+"/user/sysUsr/modifyCurrentLoginUserInfo.do",
            success:function(msg){
                if(msg.success == 1){
                    $.cookie("liger-home-tab", "", {path:'/'});
                    window.location.reload();
                }else if(msg.success==403) {
                    window.location.href = "<%=path%>/login/login/toLoginPage.do";
                } else{
                    ligerDialogSuc(msg.info, 3000);
                }
            }
        });
    });

    function showSideNav () {
            $sideNav.css({
                'visibility': 'visible',
                'top': headNnav_H
            }).show();
            setTabContent ()
    }
    function closeSideNav () {
            $sideNav.css('visibility', 'hidden').hide();
            setTabContent ()
    }
    function setTabContent () {
        if ($('.sideNav:visible').length) {
                $('.l-tab-content').css({
                    'padding-left': $sideNav.width() + parseInt($sideNav.css('left'))
                });
            } else{
                $('.l-tab-content').css({
                    'padding-left': 0
                });
            };
        tab.onResize();
    }

    function f_addTab(tabid, text, url) {
        tab.addTabItem({
            tabid: tabid,
            text: text,
            url: url
        });
    }
    // window.f_addTab = f_addTab;

    function pages_init() {
        var tabJson = $.cookie('liger-home-tab');
        if (tabJson) {
            var tabitems = JSON2.parse(tabJson);
            for (var i = 0; tabitems && tabitems[i]; i++) {
                f_addTab(tabitems[i].tabid, tabitems[i].text, tabitems[i].url);
            }
            if (tabitems.length > 0) {
                var lastTabID = tabitems[tabitems.length-1].tabid;
                changeSideNav (lastTabID);
            };
            navTabCompleted = true;
        };
    }

    function setNanoScroller () {
        setSideNavHeight ();
        $(".sideNav .nano").nanoScroller({
            preventPageScrolling: true
        });
    }
    function setSideNavHeight () {
        var newSideNavHeight = $(window).height() - headNnav_H;
        $('.sideNav').height(newSideNavHeight);
    }
    function changeSideNav (tabid) {
        var $selectedSideNav = $('#accordion1 [tabid='+tabid+']');
        $('#accordion1 .l-link').removeClass('l-link-selected');
        if ($selectedSideNav.length) {
            $selectedSideNav.addClass('l-link-selected');
            if ($selectedSideNav.parent(':visible').length == 0) {
                $selectedSideNav.parent().prev().click();
            };
        }else{
            $('.l-accordion-toggle-open-head').click();
        };
    }
    function saveTabStatus() {
    	$.cookie('liger-home-tab', JSON2.stringify(tabItems),{ path: '/'});
    }
    function getQueryString(name) {
        var now_url = document.location.search.slice(1),
            q_array = now_url.split('&');
        for (var i = 0; i < q_array.length; i++) {
            var v_array = q_array[i].split('=');
            if (v_array[0] == name) {
                return v_array[1];
            }
        }
        return false;
    }

    function usrLoginOut() {
        var _sysCd,_SQID;
        var cookies =$.cookie('webSQID');
        if(cookies){
            var split = cookies.split("_");
            if(2 === split.length){
                _sysCd = split[0];
                _SQID = split[1];
            }
        }
        $.ajax({
            type: 'get',
            headers:{
                sysCd:_sysCd,
                SQID: _SQID
            },
            url: <%=authServerPath%>+"/user/sysUsr/loginOut.do" ,

            success:function(msg){
                if(msg.success == 1){
                    $.cookie("liger-home-tab", "", {path:'/'});
                    $.cookie("FL_SQID", "", {path:'/'});
                    window.location.reload();
                }else{
                    ligerDialogSuc(msg.info, 3000);
                }
            }
        });
    }

</script>
</body>
</html>
